/*
 * Copyrignt (c) xuzeshui.com. All Rights Reserved.
 * Author: Zeshui Xu<i@xuzeshui.com>
 * Created Time: 2015-09-29 20:11:44
 * Last Modified: 2016-12-01 17:15:46
 * File Name: db/db.go
 * Description:
 */
package db

import (
	"doubimeizhi.com/utility"

	"github.com/astaxie/beego"
)

var (
	qkleagueMysqlHelper *utility.MySQLHelper
)

func createQKLeagueMySQLHelper() bool {
	mysqlHost := beego.AppConfig.DefaultString("qingke::mysql_host", "127.0.0.1")
	mysqlPort := beego.AppConfig.DefaultInt("qingke::mysql_port", 4100)
	mysqlUser := beego.AppConfig.DefaultString("qingke::mysql_user", "root")
	mysqlPass := beego.AppConfig.DefaultString("qingke::mysql_password", "")
	mysqlDB := beego.AppConfig.DefaultString("qingke::mysql_db", "qingke")
	maxOpenConns := beego.AppConfig.DefaultInt("qingke::mysql_maxOpenConns", 10)
	maxIdleConns := beego.AppConfig.DefaultInt("qingke::mysql_maxIdleConns", 5)
	qkleagueMysqlHelper = utility.NewMySQLHelper(mysqlHost, mysqlPort, mysqlUser, mysqlPass, mysqlDB, maxOpenConns, maxIdleConns)
	return true
}

func GetQKLeagueMySQLHelper() *utility.MySQLHelper {
	if qkleagueMysqlHelper == nil {
		createQKLeagueMySQLHelper()
	}
	return qkleagueMysqlHelper
}

func init() {
	GetQKLeagueMySQLHelper()
}
